#pragma once
#include"RBTree.h"
namespace ns_self{
	template<class K, class V>
	class map {
		//仿函数，传入红黑树，用作泛型的比较
		struct MapKeyOfVal {
			const K& operator()(const pair<K, V>& kv) {
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfVal>::iterator iterator;//正向迭代器	
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfVal>::reverse_iterator reverse_iterator;//反向迭代器


		iterator begin() {
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		reverse_iterator rbegin() {
			return _t.rbegin();
		}

		reverse_iterator rend()
		{
			return _t.rend();
		}


		pair<iterator, bool> insert(const pair<const K, V>& kv) {
			return _t.Insert(kv);
		}


		iterator find(const K& key)
		{
			return _t.Find(key);
		}

		V& operator[](const K& key) {
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;
		}


	private:
		RBTree<K, pair<const K, V>, MapKeyOfVal> _t;
	};
}